<template>
  <div>
    <!-- <div class="title">
      <div class="line"></div>
      <p>快捷登录</p>
      <div class="line"></div>
    </div> -->
    <div class="icon">
      <van-icon class="icon-base icon-wecaht"
                name="weixin"
                @click.native="wechatLogin" />
      <!-- <van-icon class=" icon-base icon-q "
                name="qq " /> -->
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { validatenull } from '@/util/validate';
import { wechatSDK } from '@/cordova/';
import { loginByWechat } from '@/api/user';
import common from '@/mixins/common.js';

export default {
  name: 'loginFooter',
  data () {
    return {
      unionId: '',
    };
  },
  mixins: [common()],
  created () { },
  computed: {
    ...mapGetters(['token', 'website', 'userInfo', 'community']),
  },
  mounted () { },
  methods: {
    wechatLogin () {
      wechatSDK().then((res) => {
        res
          .login()
          .then(res => loginByWechat(res.code))
          .then((res) => {
            const data = res.data.data;
            this.unionId = data.unionid;
            this.$store.commit('SET_UNIONID', this.unionId);
            return this.$store.dispatch('getAuth');
          })
          .then(() => {
            if (validatenull(this.token)) {
              this.$router.push({ path: '/user/reg' });
            } else {
              this.goAuth();
            }
          })
          .catch((err) => {
            this.$toast.fail(JSON.stringify(err));
          });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>

